package com.sirun.cn.fca.repo;

import com.sirun.cn.fca.module.main.home.temp.VehicleRespons;
import com.sirun.cn.fca.module.main.home.temp.repo.ControlPollingResponse;
import com.sirun.cn.fca.module.main.home.temp.repo.ControlRequest;
import com.sirun.cn.fca.module.main.home.temp.repo.ControlResponse;
import com.tencent.cloud.iov.kernel.constant.ApiConst;
import com.tencent.cloud.iov.kernel.model.BaseResponse;
import com.tencent.cloud.iov.kernel.service.ServiceGenerator;
import com.tencent.cloud.iov.kernel.service.interceptor.ExceptionTransformer;

import io.reactivex.Observable;

public class HomeRepository {
    private static volatile HomeRepository sInstance;

    public static HomeRepository getInstance() {
        if (sInstance == null) {
            synchronized (HomeRepository.class) {
                if (sInstance == null) {
                    sInstance = new HomeRepository();
                }
            }
        }

        return sInstance;
    }

    private final HomeService mHomeService;

    private HomeRepository() {
        mHomeService = ServiceGenerator.createService(HomeService.class, ApiConst.getBaseUrl());
    }

    public Observable<BaseResponse<ControlResponse>> controlDoor(String din, ControlRequest request) {
        return mHomeService.controlDoor(din, request)
                .compose(new ExceptionTransformer<ControlResponse>());
    }

    public Observable<BaseResponse<ControlResponse>> controlEngine(String din, ControlRequest request) {
        return mHomeService.controlEngine(din, request)
                .compose(new ExceptionTransformer<ControlResponse>());
    }

    public Observable<BaseResponse<ControlResponse>> controlBeer(String din, ControlRequest request) {
        return mHomeService.controlBeer(din, request)
                .compose(new ExceptionTransformer<ControlResponse>());
    }

    public Observable<BaseResponse<ControlPollingResponse>> controlPolling(String din, String platformResponseId) {
        return mHomeService.controlPolling(din, platformResponseId)
                .compose(new ExceptionTransformer<ControlPollingResponse>());
    }

    public Observable<BaseResponse<ControlResponse>> controlCar(String type, String din, ControlRequest request) {
        return mHomeService.controlCar(type, din, request)
                .compose(new ExceptionTransformer<ControlResponse>());
    }

    public Observable<BaseResponse<VehicleRespons>> getVehicele() {
        return mHomeService.getVehicle()
                .compose(new ExceptionTransformer<VehicleRespons>());
    }
}
